#import "TVAnswerDialogController.h"

@implementation TVAnswerDialogController

- (NSString*)show:(NSString*)promptText rightButton:(NSString*)rbText middleButton:(NSString*)mbText leftButton:(NSString*)lbText
{
    NSRect          windowBox = [[promptField window] frame];
    NSRect          textfieldBox;
    NSRect          oldTextfieldBox;
    
    [promptField setStringValue: promptText];

	// Set Button Titles
	
	if ( [rbText isEqualToString:@""] )
	{
		[button1 setTitle:@"OK"];
	}
	else
	{
		[button1 setTitle:rbText];
	}
	
	if ( ! [mbText isEqualToString:@""] )
	{
		[button2 setHidden:NO];
		[button2 setTitle:[button1 title]];
		[button1 setTitle:mbText];
	}
	else
	{
		[button2 setHidden:YES];
	}
	
	if ( ! [lbText isEqualToString:@""] )
	{
		[button3 setHidden:NO];
		[button3 setTitle:[button2 title]];
		[button2 setTitle:[button1 title]];
		[button1 setTitle:lbText];
	}
	else
	{
		[button3 setHidden:YES];
	}
	
	oldTextfieldBox = [promptField frame];
	textfieldBox = oldTextfieldBox; 
	windowBox = [[promptField window] frame];
	
	textfieldBox.size.height = 10000.0; // an arbitrary large number
	textfieldBox.size = [[promptField cell] cellSizeForBounds:textfieldBox];
	
	if(NSHeight(textfieldBox) > NSHeight(oldTextfieldBox))
		windowBox.size.height += (NSHeight(textfieldBox) - NSHeight(oldTextfieldBox));
	
	[[promptField window] setFrame:windowBox display:NO];
	
    int result = [NSApp runModalForWindow: [promptField window]];
    NSLog( @"Button %d clicked.", result );
    
    [[promptField window] orderOut: nil];   // Hide window until next use.
	//return [editField stringValue]; 	
	
	if ( result = 1 )
	{
		return [button1 title];
	}
	else if ( result = 2 )
	{
		return [button2 title];
	}
	else
	{
		return [button3 title];
	}
}


- (IBAction)buttonClicked:(id)sender
{
	NSLog( @"Clicked: %@", [sender title] );
    [NSApp stopModalWithCode: [sender tag]];
}

@end
